/**
 * @author zhu
 * @date 2024-03-20
 */
public class MyThread implements Runnable{
    private int ticketCount = 50;
    private final static Object LOCK = new Object();
    @Override
    public void run() {
        while(ticketCount>=1) {
            synchronized (LOCK){
                if(ticketCount > 0) {
                    System.out.println(Thread.currentThread().getName() + "出售了第 " + ticketCount + " 张票");
                    ticketCount -- ;
                }
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
